home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Strings / PString.cp < prev    next >
Text File  |  1997-06-28  |  3KB  |  131 lines

  1. // PString.cp
  2.  
  3. #ifndef PString_h
  4. #include "PString.h"
  5. #endif
  6.  
  7. PString::PString( Data theSpace )
  8.   : space( theSpace )
  9.   {
  10.     Assert( !space.Null() );
  11.     Assert( StorageLength() <= maxuint8 + 1 );
  12.     Assert( Length() < StorageLength() );
  13.   }
  14.  
  15. PString::PString( Data theSpace, ConstStr255Param text )
  16.   : space( theSpace )
  17.   {
  18.     Assert( !space.Null() );
  19.     Assert( StorageLength() <= maxuint8 + 1 );
  20.     Assert( text[0] < StorageLength() );
  21.     if ( text != space.Start() )
  22.         space << ConstData( text, text[0]+1 );
  23.   }
  24.  
  25. PString::PString( Data theSpace, ConstPString text )
  26.   : space( theSpace )
  27.   {
  28.     Assert( !space.Null() );
  29.     Assert( StorageLength() <= maxuint8 + 1 );
  30.     Assert( text.Length() < StorageLength() );
  31.     space << ConstData( text, text.Length()+1 );
  32.   }
  33.  
  34. PString::PString( Data theSpace, PString text )
  35.   : space( theSpace )
  36.   {
  37.     Assert( !space.Null() );
  38.     Assert( StorageLength() <= maxuint8 + 1 );
  39.     Assert( text.Length() < StorageLength() );
  40.     space << ConstData( text, text.Length()+1 );
  41.   }
  42.  
  43. PString::PString( Data theSpace, ConstData text )
  44.   : space( theSpace )
  45.   {
  46.     Assert( !space.Null() );
  47.     Assert( StorageLength() <= maxuint8 + 1 );
  48.     Assert( text.Length() < StorageLength() );
  49.     space[0] = TextSpace() << text;
  50.   }
  51.  
  52. void PString::Truncate( uint32 end )
  53.   {
  54.     if ( Length() > end )
  55.         space[0] = end;
  56.   }
  57.  
  58. void PString::SetLength( uint32 newLength )
  59.   {
  60.     Assert( newLength < StorageLength() );
  61.     space[0] = newLength;
  62.   }
  63.  
  64. void PString::operator=( ConstData text )
  65.   {
  66.     Assert( text.Length() < StorageLength() );
  67.     space[0] = TextSpace() << text;
  68.   }
  69.  
  70. void PString::operator+=( uint8 c )
  71.   {
  72.     Assert( Length() + 1 < StorageLength() );
  73.     if ( Length() + 1 < StorageLength() )
  74.         space[ ++space[0] ] = c;
  75.   }
  76.  
  77. void PString::operator+=( ConstData text )
  78.   {
  79.     Assert( Length() + text.Length() < StorageLength() );
  80.     space[0] += UnusedSpace() << text;
  81.   }
  82.  
  83. void PString::Remove( URange32 range )
  84.   {
  85.     Assert( range.End() <= Length() );
  86.     space[0] -= range.Length();
  87.     SpaceTail( range.Start() ) << Tail( range.End() );
  88.   }
  89.  
  90. void PString::Insert( uint32 where, uint8 c )
  91.   {
  92.     Assert( Length() + 1 < StorageLength() );
  93.     Assert( where <= Length() );
  94.     
  95.     SpaceTail( where+1 ) << Tail( where );
  96.     (*this)[ where ] = c;
  97.     space[ 0 ]++;
  98.   }
  99.  
  100. void PString::Insert( uint32 where, ConstData text )
  101.   {
  102.     Assert( Length() + text.Length() < StorageLength() );
  103.     Assert( where <= Length() );
  104.     
  105.     SpaceTail( where + text.Length() ) << Tail( where );
  106.     SpaceTail( where ) << text;
  107.     space[ 0 ] += text.Length();
  108.   }
  109.  
  110. void PString::Replace( URange32 range, uint8 c )
  111.   {
  112.     Assert( range.End() <= Length() )
  113.     Assert( Length() - range.Length() + 1 < StorageLength() );
  114.     
  115.     SpaceTail( range.Start() + 1 ) << Tail( range.End() );
  116.     (*this)[ range.Start() ] = c;
  117.     space[ 0 ] -= range.Length();
  118.     space[ 0 ] ++;
  119.   }
  120.  
  121. void PString::Replace( URange32 range, ConstData text )
  122.   {
  123.     Assert( range.End() <= Length() )
  124.     Assert( Length() - range.Length() + text.Length() < StorageLength() );
  125.     
  126.     SpaceTail( range.Start() + text.Length() ) << Tail( range.End() );
  127.     SpaceTail( range.Start() ) << text;
  128.     space[ 0 ] -= range.Length();
  129.     space[ 0 ] += text.Length();
  130.   }
  131.